#ifndef _OMX_OSA_POSIX_H_
#define _OMX_OSA_POSIX_H_
#include <stdio.h>
#include <pthread.h>
typedef pthread_t omx_thread;
typedef pthread_attr_t omx_thread_attr;
typedef pthread_mutex_t omx_thread_mutex;
typedef pthread_mutexattr_t omx_thread_mutexattr;
typedef pthread_cond_t omx_thread_cond;
typedef pthread_condattr_t omx_thread_condattr;

typedef struct omx_sem
{
    omx_thread_cond condition;
    omx_thread_mutex mutex;
    unsigned int semval;
} omx_sem;

typedef FILE omx_file;

int omx_thread_create(omx_thread * tid, const omx_thread_attr * attr, void *(*start) (void *),void *arg);
int omx_thread_join(omx_thread *thread,void **value_ptr);
int omx_thread_cancel(omx_thread *threadId);
int omx_thread_mutex_init(omx_thread_mutex * mutex, const omx_thread_mutexattr * attr);
int omx_thread_mutex_lock(omx_thread_mutex * mutex);
int omx_thread_mutex_unlock(omx_thread_mutex * mutex);
int omx_thread_mutex_destroy(omx_thread_mutex * mutex);
int omx_thread_cond_wait(omx_thread_cond * cond, omx_thread_mutex * mutex);
int omx_thread_cond_signal (omx_thread_cond * cond);
int omx_thread_cond_init(omx_thread_cond * cond, const omx_thread_condattr * attr);
int omx_thread_cond_destroy(omx_thread_cond * cond);
int omx_usleep(unsigned int time);


/** Initializes the semaphore at a given value
 *
 * @param tsem the semaphore to initialize
 *
 * @param val the initial value of the semaphore
 */
void omx_sem_init(omx_sem *tsem, unsigned int val);
/** Destroy the semaphore
 *
 * @param tsem the semaphore to destroy
 */
void omx_sem_deinit(omx_sem *tsem);
/** Decreases the value of the semaphore. Blocks if the semaphore
 * value is zero.
 *
 * @param tsem the semaphore to decrease
 */
void omx_sem_down(omx_sem *tsem);
/** Increases the value of the semaphore
 *
 * @param tsem the semaphore to increase
 */
void omx_sem_up(omx_sem *tsem);
/** Reset the value of the semaphore
 *
 * @param tsem the semaphore to reset
 */
void omx_sem_reset(omx_sem *tsem);
/** Wait on the condition.
 *
 * @param tsem the semaphore to wait
 */
void omx_sem_wait(omx_sem *tsem);
/** Signal the condition,if waiting
 *
 * @param tsem the semaphore to signal
 */
void omx_sem_signal(omx_sem *tsem);
int omx_sem_count(omx_sem *tsem);

void *omx_malloc(unsigned int size);
void *omx_calloc(unsigned int nBlock,size_t size);
unsigned int omx_free(void *ptr);


omx_file  *omx_file_open(const char *filename, const char *mode);
void  omx_file_close(omx_file *handle);
unsigned int omx_file_read(void *buffer, unsigned int nBlock, unsigned int size, omx_file *handle);
unsigned int omx_file_write(void *buffer, unsigned int nBlock, unsigned int size, omx_file *handle);
void  omx_Dprintf(int n,char *format,...);
#endif //end _OMX_OSA_POSIX_H_
